package com.yupi.yuapicommon.model.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 通用返回类
 *
 * @param <T>
 * @author yupi
 */
@Data
@ApiModel
public class BaseResponse<T> implements Serializable {
    @ApiModelProperty(name = "状态码   ",
            value = "200: 请求成功   " +
                    "40000: 请求参数错误   " +
                    "40100: 未登录   " +
                    "40101: 无权限   " +
                    "40001: 账号已封禁   " +
                    "40401: 禁止访问   " +
                    "40400: 请求接口返回结果异常   " +
                    "40300: 禁止访问   " +
                    "50000: 系统内部异常   " +
                    "50001: 操作失败  " +
                    "50005: IP在黑名单内/请求时间戳过期/没有权限/羊毛积分不足")
    private int code;

    private T data;

    private String message;

    public BaseResponse(int code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public BaseResponse(int code, T data) {
        this(code, data, "");
    }

    public BaseResponse(ErrorCode errorCode) {
        this(errorCode.getCode(), null, errorCode.getMessage());
    }
}
